package com.ruoyi.zyx.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxOrderBill;
import com.ruoyi.zyx.service.IZyxOrderBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回单Controller
 * 
 * @author ruoyi
 * @date 2021-06-17
 */
@RestController
@RequestMapping("/zyx/bill")
public class ZyxOrderBillController extends BaseController
{
    @Autowired
    private IZyxOrderBillService zyxOrderBillService;

    /**
     * 查询回单列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxOrderBill zyxOrderBill)
    {
        startPage();
        List<ZyxOrderBill> list = zyxOrderBillService.selectZyxOrderBillList(zyxOrderBill);
        return getDataTable(list);
    }

    /**
     * 导出回单列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:bill:export')")
    @Log(title = "回单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxOrderBill zyxOrderBill)
    {
        List<ZyxOrderBill> list = zyxOrderBillService.selectZyxOrderBillList(zyxOrderBill);
        ExcelUtil<ZyxOrderBill> util = new ExcelUtil<ZyxOrderBill>(ZyxOrderBill.class);
        return util.exportExcel(list, "回单数据");
    }

    /**
     * 获取回单详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:bill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxOrderBillService.selectZyxOrderBillById(id));
    }


    @GetMapping(value = "/getInfoBySendorderid/{sendorderid}")
    public AjaxResult getInfoBySendorderid(@PathVariable("sendorderid") Long sendorderid)
    {
        return AjaxResult.success(zyxOrderBillService.getInfoBySendorderid(sendorderid));
    }

    /**
     * 新增回单
     */
    @PreAuthorize("@ss.hasPermi('zyx:bill:add')")
    @Log(title = "回单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxOrderBill zyxOrderBill)
    {
        return toAjax(zyxOrderBillService.insertZyxOrderBill(zyxOrderBill));
    }

    /**
     * 修改回单
     */

    @Log(title = "回单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxOrderBill zyxOrderBill)
    {
        return toAjax(zyxOrderBillService.updateZyxOrderBill(zyxOrderBill));
    }

    /**
     * 删除回单
     */
    @PreAuthorize("@ss.hasPermi('zyx:bill:remove')")
    @Log(title = "回单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxOrderBillService.deleteZyxOrderBillByIds(ids));
    }
}
